
$(function () {
         var order_tab = $(".order_tab");
         var userName = localStorage.getItem("user");
       // window.onload = view();
         $.ajax({
            url : "easybuy/product/showCollect",
            type : "post",
            data : {"userName":userName},
            dataType : "json",
            success : function (data) {
                if(data !=null){
                    for(var i=0;i<data.length;i++){
                        var th = "<tr><td style=\"font-family:'宋体';\">";
                        th += "<div class=\"sm_img\"><img src='../images/"+data[i].fileName+"' width=\"48\" height=\"48\" /></div>" +
                            "<span>"+data[i].name+"</span></td>";
                        th += "<td align=\"center\">"+accounting.formatMoney(data[i].price, "￥",1, ",", ".")+"</td>"
                        th += "<td align=\"center\"><a href=\"#\">关注</a>&nbsp; &nbsp; " +
                            "<a href=\"#\" style=\"color:#ff4e00;\">加入购物车</a>&nbsp; &nbsp; " +
                            "<a href=\"#\" onclick='del("+data[i].id+")'>删除</a></td></tr>\n"
                        order_tab.append(th);
                    }

                }
            },
            error : function (XMLHttpRequest, textStatus, errorThrown) {
                alert("出现错误");
                console.log(XMLHttpRequest.status);
                console.log(XMLHttpRequest.readyState);
                console.log(textStatus);
            }
        });

});

function del(id){
    var order_tab = $(".order_tab");
    var userName = localStorage.getItem("user");
    $.ajax({
        url : "easybuy/product/delMemId",
        data : {"id" : id,"userName" : userName},
        dataType: "json",
        type : "post",
        success : function (data) {
            if(data.del=="success"){
                alert("删除成功");
                order_tab.html("");
                location.reload();
            }else{
                alert("删除失败");
            }
        },
        error : function (XMLHttpRequest, textStatus, errorThrown) {
            alert("出现错误");
            console.log(XMLHttpRequest.status);
            console.log(XMLHttpRequest.readyState);
            console.log(textStatus);
        }

    })
}
